package num26;

import java.util.Arrays;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 18:00
 * @Desc : https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/submissions/
 * 默认已排好序
 */
public class Solution {
  public int removeDuplicates(int[] nums) {
    int distinctIndex = 1;
    for (int i = 1; i < nums.length; i++) {
      if (nums[i - 1] != nums[i]) {
        nums[distinctIndex++] = nums[i];
      }
    }
    return distinctIndex;
  }

  public static void main(String[] args) {
    int[] nums = {0,0,1,1,1,2,2,3,3,4};
    int res = new Solution().removeDuplicates(nums);
    System.out.println(res);
    System.out.println(Arrays.toString(nums));
  }
}
